import * as T from '../src/const.js'
import * as C from '../src/const.js'
import assert from 'assert'

describe('Calc', function() {
  describe('calc', function() {
    it('', function() {
      console.log(T.BIT_TYPE)
      console.log(C.CHESS_MAP.get(C.T_ZHAO))
    })
  })

  describe('map', function() {
    it('', function() {
      let m = new Map()
      m.set(1, "black")
      m.set(2, "red")
      console.log(m)
      for (let key of m.keys()) {
        console.log(m.get(key));
      }
      assert.equal("aaaaa", "aaaaa")
    })
  })

  describe('array_concat', function() {
    it('', function() {
      let a = [0, 1, 2, 3, 4]
      let b = [5, 6, 7, 8, 9]
      let c = a.concat(b)
      assert.equal(c.length, 10)
      console.log(200 / 300)
    })
  })

  describe('graph', function() {
    it('', function() {
      class Node {
        constructor(v) {
          this.v = v
          this.pre = null
        }
        key() {
          return this.v
        }
      }
      function get_next(graph, current) {
        let next = new Array()
        for (let i = 0; i < graph[0].length; i++) {
          if (current.v != i && graph[current.v][i] == 1) {
            let tmp = new Node(i)
            tmp.pre = current
            next.push(tmp)
          }
        }
        return next
      }
      let graph = [
        //      0  1  2  3  4  5  6
       /* 0 */ [1, 1, 1, 0, 0, 1, 0],
       /* 1 */ [1, 1, 0, 1, 1, 0, 0],
       /* 2 */ [1, 0, 1, 1, 0, 0, 0],
       /* 3 */ [0, 1, 1, 1, 1, 0, 0],
       /* 4 */ [0, 1, 0, 1, 1, 0, 1],
       /* 5 */ [1, 0, 0, 0, 0, 1, 1],
       /* 6 */ [0, 0, 0, 0, 1, 1, 1]
      ]
      let start = new Node(0)
      let end = new Node(4)
      let queue = new Array()
      let visited = new Set()
      visited.add(start.key())
      queue.push(start)
      let finish = null
      while (queue.length != 0) {
        let current = queue.shift()
        if (current.v == end.v) {
          finish = current
          break
        } else {
          let next_list = get_next(graph, current)
          for (let a of next_list) {
            let key = a.key()
            if (!visited.has(key)) {
              queue.push(a)
              visited.add(key)
            }
          }
        }
      }
      let result = new Array()
      while (finish != null) {
        result.unshift(finish)
        finish = finish.pre
      }
      for (let r of result) {
        console.log(r.v)
      }
    })
  })
})